package com.tepth.busfix.main.home;

import com.tepth.busfix.bean.reponse.BusType;
import com.tepth.busfix.bean.reponse.TroubleContent;
import com.tepth.busfix.network.ApiModel;
import com.tepth.busfix.network.observer.SimpleDisposableObserver;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by TMVPHelper on 2017/03/13
 */
public class HomePresenter extends HomeContract.Presenter {

    @Override
    void getBusType() {
        mRxManager.add(mModel.getBusType(mView.getAuthKey()).
                subscribeWith(new SimpleDisposableObserver<ApiModel<List<BusType>>>(mView) {

                    @Override
                    public void onSucceed(Object o) {
                        ArrayList<BusType> list = (ArrayList<BusType>) o;
                        mView.setBusType(list);
                    }
                }));
    }

    @Override
    void getOperationList() {
        mRxManager.add(mModel.getOperationList(mView.getAuthKey()).
                subscribeWith(new SimpleDisposableObserver<ApiModel<List<TroubleContent.Operation>>>(mView) {

                    @Override
                    public void onSucceed(Object o) {
                        ArrayList<TroubleContent.Operation> list = (ArrayList<TroubleContent.Operation>) o;
                        mView.setOperationList(list);
                    }
                }));
    }

    @Override
    void startRepair() {
        mRxManager.add(mModel.startRepair(mView.getAuthKey(),mView.getBody()).
                subscribeWith(new SimpleDisposableObserver<ApiModel<String>>(mView) {

                    @Override
                    public void onSucceed(Object o) {
                        mView.startRepairSucceed();
                    }
                }));
    }
}